﻿using BCCommon;
using BCDto.Common.ErrorMessage;
using BCDto.TMS.Driver.DriverLearnDatum;
using BCService.TMS.Driver.DriverLearnDatum;
using BCTMSRESTful.Configs;
using BCTMSRESTful.Controllers.Management;
using Microsoft.AspNetCore.Mvc;

namespace BCTMSRESTful.Controllers.Management.Driver
{
    /// <summary>
    /// 司机学习资料答案
    /// </summary>
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class DriverLearnDatumAnswersController : ManagementBaseController
    {
        private readonly IDriverLearnDatumAnswerService datumAnswerService;

        public DriverLearnDatumAnswersController(IDriverLearnDatumAnswerService datumAnswerService)
        {
            this.datumAnswerService = datumAnswerService;
        }

        /// <summary>
        /// 带有分页信息的一组司机学习资料答案
        /// </summary>
        /// <param name="index">分页第一也索引</param>
        /// <param name="size">分页行数</param>
        /// <param name="answerContent">学习资料答案内容</param>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(PageableList<DriverLearnDatumAnswerDto>), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult GetDriverLearnDatumAnswers([FromQuery(Name = "index")] int index = 1, [FromQuery(Name = "size")] int size = 10, [FromQuery(Name = "answer_content")] string answerContent = null)
        {
            return Ok(datumAnswerService.GetDriverLearnDatumAnswers(index, size, answerContent));
        }

        /// <summary>
        /// 查询指定的学习资料答案信息
        /// </summary>
        /// <param name="datumAnswerId">学习资料答案编号</param>
        /// <returns></returns>
        [HttpGet("{datum_answer_id}")]
        [ProducesResponseType(typeof(DriverLearnDatumAnswerDto), 201)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult GetDatumAnswerById(int datumAnswerId)
        {
            return Ok(datumAnswerService.GetDriverLearnDatumAnswerById(datumAnswerId));
        }

        /// <summary>
        /// 新增学习资料答案
        /// </summary>
        /// <param name="datumAnswer">学习资料答案编号</param>
        /// <returns></returns>
        [HttpPost]
        [Log("新增学习资料答案")]
        [ProducesResponseType(typeof(DriverLearnDatumAnswerDto), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult Post([FromBody] DriverLearnDatumAnswerRequestDto datumAnswer)
        {
            var id = datumAnswerService.Add(datumAnswer);
            var result = datumAnswerService.GetDriverLearnDatumAnswerById(id);
            return Created(string.Format("/api/v1/sim/DriverLearnDatumAnswers/{0}", id), result);
        }

        /// <summary>
        /// 更新指定的学习资料答案
        /// </summary>
        /// <param name="datumAnswerId">学习资料答案编号</param>
        /// <param name="dto">学习资料答案内容</param>
        /// <returns></returns>
        [HttpPut("{datum_answer_id}")]
        [Log("更新指定的学习资料答案")]
        [ProducesResponseType(typeof(DriverLearnDatumAnswerDto), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult Put([FromRoute(Name = "datum_answer_id")] int datumAnswerId, [FromBody] DriverLearnDatumAnswerRequestDto dto)
        {
            return Ok(datumAnswerService.Update(this.Admin, datumAnswerId, dto));
        }

    }
}
